#include "chassis/recorder.hpp"
#include <chrono>

using namespace std;

Recorder::~Recorder()
{
    if (file.is_open())
        Save();
}

bool Recorder::SetPath(std::string path)
{
    file = ofstream(path);
    if (!file.is_open())
    {
        return false;
    }
    return true;
}

void Recorder::SaveTime()
{
    file << std::chrono::steady_clock::now().time_since_epoch().count() << ',';
}

void Recorder::SaveInt(int value)
{
    file << value << ',';
}

void Recorder::SaveFloat(float value)
{
    file << value << ',';
}

void Recorder::SaveString(std::string str)
{
    file << str << ',';
}

void Recorder::CreatTitle(std::vector<std::string> titles)
{
    for (string title : titles)
    {
        SaveString(title);
    }
    NewLine();
}

void Recorder::NewLine()
{
    file.seekp(-1, ios_base::end);
    file << endl;
    lines++;
}

void Recorder::Save()
{
    file.close();
}